{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-01-08 16:08:34,541 P[5908] [MainThread 2964] Error: no proxy address identified.\n",
      "Check if Eikon Desktop or Eikon API Proxy is running.\n",
      "2022-01-08 16:08:34,543 P[5908] [MainThread 2964] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol(\"Request URL is missing an 'http://' or 'https://' protocol.\")\n",
      "2022-01-08 16:08:34,544 P[5908] [MainThread 2964] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol(\"Request URL is missing an 'http://' or 'https://' protocol.\")\n",
      "2022-01-08 16:08:34,544 P[5908] [MainThread 2964] Port number was not identified, cannot send any request\n"
     ]
    }
   ],
   "source": [
    "import eikon\n",
    "eikon.set_app_key('xxxxxxxxxxxxxxxxxxxxxxx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from realtime_talib import Indicator\n",
    "\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar, Timeline\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.faker import Faker\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.read_excel('C:/Users/zhang/Desktop/stock.xls',index_col = 'date' ,date_parser='date')\n",
    "trainDF_Ascending = df.sort_index(ascending=True) #日期升序\n",
    "trainDF_Descending = df.sort_index(ascending=False) #日期降序\n",
    "\n",
    "def date_range(start_date,end_date):\n",
    "    for n in range(int((end_date-start_date).days)):\n",
    "        yield start_date+datetime.timedelta(n)\n",
    "\n",
    "\n",
    "\n",
    "start=datetime.datetime(2021,1,1,0,0,0)\n",
    "end=datetime.datetime(2021,12,31,0,0,0)\n",
    "\n",
    "# for day in date_range(start, end):\n",
    "#     print(day.strftime('%Y-%m-%d'))\n",
    "#     ppt=trainDF_Ascending[day:day].groupby('code').sum().sort_values(by='rate').tail(10)\n",
    "#     print(ppt)\n",
    "#     # for i in pd.date_range('20210101', '20211230',freq='YS')\n",
    "#     for row in ppt.itertuples():\n",
    "#         print(row.Index,getattr(row, 'rate'), getattr(row, 'price')) # 输出每一行\n",
    "        \n",
    "#     bar = (\n",
    "#         Bar()\n",
    "#         .add_xaxis(pd.Series(ppt['rate'], index=ppt.index))\n",
    "#         .add_yaxis(\"商家A\", Faker.values())\n",
    "#         .set_global_opts(\n",
    "#             title_opts=opts.TitleOpts(\"某商店{}年营业额 - With Graphic 组件\".format(i)),\n",
    "#             graphic_opts=[\n",
    "#                 opts.GraphicGroup(\n",
    "#                     graphic_item=opts.GraphicItem(\n",
    "#                         rotation=JsCode(\"Math.PI / 4\"),\n",
    "#                         bounding=\"raw\",\n",
    "#                         right=100,\n",
    "#                         bottom=110,\n",
    "#                         z=100,\n",
    "#                     ),\n",
    "#                     children=[\n",
    "#                         opts.GraphicRect(\n",
    "#                             graphic_item=opts.GraphicItem(\n",
    "#                                 left=\"center\", top=\"center\", z=100\n",
    "#                             ),\n",
    "#                             graphic_shape_opts=opts.GraphicShapeOpts(\n",
    "#                                 width=400, height=50\n",
    "#                             ),\n",
    "#                             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(\n",
    "#                                 fill=\"rgba(0,0,0,0.3)\"\n",
    "#                             ),\n",
    "#                         ),\n",
    "#                         opts.GraphicText(\n",
    "#                             graphic_item=opts.GraphicItem(\n",
    "#                                 left=\"center\", top=\"center\", z=100\n",
    "#                             ),\n",
    "#                             graphic_textstyle_opts=opts.GraphicTextStyleOpts(\n",
    "#                                 text=\"某商店{}年营业额\".format(i),\n",
    "#                                 font=\"bold 26px Microsoft YaHei\",\n",
    "#                                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(\n",
    "#                                     fill=\"#fff\"\n",
    "#                                 ),\n",
    "#                             ),\n",
    "#                         ),\n",
    "#                     ],\n",
    "#                 )\n",
    "#             ],\n",
    "#         )\n",
    "#     )\n",
    "#     tl.add(bar, \"{}年\".format(i))\n",
    "# tl.render(\"timeline_bar_with_graphic.html\")\n",
    "\n",
    "OHLCV = df\n",
    "rt_BBANDS = Indicator(OHLCV, \"BBANDS\", 2, 2, 5, 3)\n",
    "rt_MA = Indicator(OHLCV, \"AROON\", 2, 1)\n",
    "\n",
    "print(rt_MA.getHistorical(lag=1))\n",
    "tickData = (2800, 2700, 2600, 2900, 9394) # format of OHLCV\n",
    "print(rt_BBANDS.getRealtime(tickData, lag=2))\n",
    "print(rt_BBANDS.getRealtime(tickData, lag=2))\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
